package com.itheima.mapper;

import com.itheima.entity.Emp;
import com.itheima.entity.EmpQueryParam;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.util.List;

@Mapper
public interface EmpMapper {
    /**
     * 查询总记录数
     * @return
     */
    /*@Select("select count(*) from emp")
    Long count();*/

    /**
     * 分页查询
     * @param start
     * @param pageSize
     * @return
     */
    /*@Select("select e.*,d.name deptName from emp e left join dept d on e.dept_id = d.id limit #{start}, #{pageSize}")
    List<Emp> page(Integer start, Integer pageSize);*/

    /**
     * 列表查询
     * @return
     */
    //@Select("select e.*,d.name deptName from emp e left join dept d on e.dept_id = d.id ")
    //基于xml开发
    List<Emp> list(EmpQueryParam  param);

    /**
     * 新增员工
     * @param emp
     */
    @Options(useGeneratedKeys = true,keyProperty = "id")  //获取主键的值，赋值给id
    @Insert("insert into emp values(null,#{username},#{password},#{name},#{gender},#{phone},#{job},#{salary},#{image}," +
            "#{entryDate},#{deptId},#{createTime},#{updateTime}) ")
    void insert(Emp emp);

    /**
     * 批量删除员工
     * @param ids
     */
    //基于xml开发 -- foreach
    void deleteBatch(List<Integer> ids);

    /**
     * 根据id查询员工
     * @param id
     * @return
     */
    /*@Select("select * from emp e left join emp_expr ee on e.id = ee.emp_id where id = e.#{id}")*/
    Emp getById(Integer id);

    /**
     * 方式2
     * @param id
     * @return
     */
    @Select("select * from emp where id = #{id}")
    Emp getById2(Integer id);

    /**
     * 修改员工
     * @param emp
     */
    //基于xml开发
    void update(Emp emp);

    /**
     * 员工登录
     * @param emp
     * @return
     */
    @Select("select * from emp where username = #{username} and password = #{password}")
    Emp selectUsernameAndPassword(Emp emp);
}
